package Year2021.month10.Day21.Day27;

//租赁公司;

import java.util.Scanner;

public class LeasingCompany {
    private String name;//名字;
    private String phone;//电话;
    private int numberOfCars;//可租赁的汽车数量;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getNumberOfCars() {
        return numberOfCars;
    }

    public void setNumberOfCars(int numberOfCars) {
        this.numberOfCars = numberOfCars;
    }

    public void show() {
        System.out.println(getName() + "欢迎您！，请致电" + getPhone() + "洽谈相关租赁业务，本公司现在有" + getNumberOfCars() + "辆车" +
                "可以租赁！");
    }

    Automobile a[] = new Automobile[20];

    public LeasingCompany() {
        a[0] = new Car("宝马", "京NY28588", 800, "当前可租", "X6");
        a[1] = new Car("宝马", "京CNY3284", 600, "当前可租", "550i");
        a[2] = new Car("别克", "京NT37465", 300, "当前可租", "林荫大道");
        a[3] = new Car("别克", "京NT96968", 600, "当前可租", "GL8");
        a[4] = new Bus("金杯", "京6566754", 800, "当前可租", 16);
        a[5] = new Bus("金龙", "京8696997", 800, "当前可租", 16);
        a[6] = new Bus("金杯", "京9696996", 1500, "当前可租", 34);
        a[7] = new Bus("金龙", "京8696998", 1500, "当前可租", 34);
    }

    //显示信息；
    public void display() {
        for (Automobile automobile : a) {
            if (automobile instanceof Car) {
                Car car = (Car) automobile;
                car.show();
            } else if (automobile instanceof Bus) {
                Bus bus = (Bus) automobile;
                bus.show();

            }
        }
    }
    //租赁;

    public void rent() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你想要租赁的类型，1:轿车,2:客车");
        int choice = in.nextInt();
        for (Automobile automobile : a) {
            if (choice == 1) {
                if (automobile instanceof Car && automobile.getCurrentState().equals("当前可租")) {
                    Car car = (Car) automobile;
                    car.show();
                }
            } else if (choice == 2) {
                if (automobile instanceof Bus && automobile.getCurrentState().equals("当前可租")) {
                    Bus bus = (Bus) automobile;
                    bus.show();
                }
            }
        }
        System.out.println("选择你要租赁的车辆，输入车牌号:");
        String k = in.next();
        boolean chepai = false;
        for (int j = 0; j < a.length; j++) {
            if (a[j] != null&&a[j].getLicensePlate().equals(k) ) {
                chepai = true;
            }
        }
        if (chepai) {
            System.out.println("请输入要租赁的天数");
            int days = in.nextInt();
            System.out.println("需要付的租金是：");
            for (int i = 0; i < a.length; i++) {
                if (a[i] instanceof Car) {
                    if (a[i] != null && a[i].getLicensePlate().equals(k)) {
                        a[i].setCurrentState("当前不可租");
                        Car car = (Car) a[i];
                        System.out.println(car.money(days));
                        break;
                    }

                } else if (a[i] instanceof Bus) {
                    Bus bus = (Bus) a[i];
                    System.out.println(bus.money(days));
                    a[i].setCurrentState("当前不可租");
                    break;

                }
            }

        } else {
            System.out.println("输入信息错误，租车失败！请重新输入！");

        }
    }


    //还车;

    public boolean returnTheCar(String k) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] != null && a[i].getLicensePlate().equals(k)) {
//                if (a[i].getCurrentState().equals("当前不可租")) {
                a[i].setCurrentState("当前可租");
                return true;
            }
        }
        return false;

    }

    //报废;
    public boolean scrap(String k1) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] != null && a[i].getLicensePlate().equals(k1)) {
                if (a[i].getCurrentState().equals("当前可租")) {
                    a[i] = null;
                    return true;
                }
            }

        }
        return false;

    }

    //采购新车;
    int pos;//当前车辆数

    public void buy(Automobile automobile) {
        if (pos >= a.length) {
            System.out.println("当前车位已满，无法添加！");
        } else {
            a[pos++] = automobile;
            System.out.println("购买新车成功！");
        }


    }
}

